package cc.edge2.sns.services;

import java.util.HashMap;
import java.util.Map;

import javax.jdo.PersistenceManager;

import net.arnx.jsonic.JSON;

import cc.edge2.sns.commons.PMF;
import cc.edge2.sns.models.SNSUser;

public class SaveProfileService {
	public String execute(Map params, SNSUser user) {
		user.setName((String)params.get("name"));
		user.setThumbnailUrl((String)params.get("thumbnailUrl"));
		user.setSelfIntroduction((String)params.get("selfIntroduction"));
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try { 
			pm.makePersistent(user);
		} finally {
			pm.close();
		}
		
		Map<String, Object> result = new HashMap<String, Object>();
		Map<String, Object> contents = new HashMap<String, Object>();
		Map<String, Object> status = new HashMap<String, Object>();
		status.put("code", "0");
		status.put("message", "success");
		contents.put("name", user.getName());
		contents.put("thumbnailUrl", user.getThumbnailUrl());
		contents.put("userId", user.getUserId());
		contents.put("currentUserId", user.getUserId());
		contents.put("selfIntroduction", user.getSelfIntroduction());
		result.put("status", status);
		result.put("contents", contents);
		String value = JSON.encode(result);
		return value;
	}
}
